﻿/*
 * zpath.cxx
 *
 *  Created on: 2015年4月3日
 *      Author: Fifi Lyu
 */

#include "zpsoe/zalgorithm/zpath.h"
#include <cstring>

namespace zpsoe {

namespace zalgorithm {

namespace zpath {
ZPSOE_SHARED_LIB_API string base_name(const string &file) {
    string ret("");

    if (file.empty())
        return ret;

    const char* sep = OS_SEPARATOR.c_str();
    const size_t pos = file.find_last_of(sep);

    if (string::npos == pos) {
        return ret;
    }

    ret = file.substr(pos + strlen(sep));
    return ret;
}

ZPSOE_SHARED_LIB_API string dir_name(const string &name) {
    string ret("");

    if (name.empty())
        return ret;

    const char* sep = OS_SEPARATOR.c_str();
    const size_t pos = name.find_last_of(sep);

    if (string::npos == pos) {
        ret = ".";
        return ret;
    }

    ret = name.substr(0, pos);
    return ret;
}

} /* namespace zpath */

} /* namespace zalgorithm */

} /* namespace zpsoe */
